<?php
namespace Common\Controller;

use Think\Controller;

/**
 * Created by IntelliJ IDEA.
 * User: fanxu(746439274@qq.com)
 * Date: 15/7/6
 * Time: 下午11:51
 */

class CoreController extends Controller{

    protected function _initialize(){
        $this->assign( 'resource_url' , __RESOURCE__ . strtolower( MODULE_NAME ) );
    }

    /**
     * @param $data
     * @param int $status
     * @return array
     */
    public function jsonReturn($data,$status=1){

        if( $status == 1 )
            return
                array(
                    'status' => $status,
                    'data' => $data,
                    'info' => []
                );
        return
            array(
                'status' => $status,
                'data' => $data,
                'info' => $data
            );
    }

    /**
     * 返回上个连接地址
     * @param $url
     */
    public function goBack( $url = __SITE__ ){
        if( strpos( $_SERVER['HTTP_REFERER'] , __SITE__ ) !== false ){
            $url = $_SERVER['HTTP_REFERER'];
        }
        return header( 'Location: ' . $url );
    }
}